/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package Presentacion;

/**
 *
 * @author Analia
 */

import Negocio.POP3;

public class FrameBandejaEntrada extends javax.swing.JFrame
{

    /** Creates new form FrameBandejaEntrada */
    
    private FramePrincipal frmPrincipalAux;
    private POP3 auxPop3;


    public FrameBandejaEntrada(FramePrincipal frmPrincipal)
    {

        this.frmPrincipalAux = frmPrincipal;
        auxPop3 = new POP3(this.frmPrincipalAux.getConfiguracion());


        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BotonListar = new javax.swing.JButton();
        BotonLeer = new javax.swing.JButton();
        BotonBorrar = new javax.swing.JButton();
        BotonSalir = new javax.swing.JButton();
        LabelTitulo = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TextArea = new javax.swing.JTextArea();
        EditNumero = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        BotonListar.setText("Listar");
        BotonListar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonListarActionPerformed(evt);
            }
        });

        BotonLeer.setText("Leer");
        BotonLeer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonLeerActionPerformed(evt);
            }
        });

        BotonBorrar.setText("Borrar");
        BotonBorrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonBorrarActionPerformed(evt);
            }
        });

        BotonSalir.setText("Salir");
        BotonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonSalirActionPerformed(evt);
            }
        });

        LabelTitulo.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N
        LabelTitulo.setText("BANDEJA DE ENTRADA");

        TextArea.setColumns(20);
        TextArea.setRows(5);
        jScrollPane1.setViewportView(TextArea);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(BotonListar)
                .addGap(38, 38, 38)
                .addComponent(EditNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                .addComponent(BotonLeer)
                .addGap(27, 27, 27)
                .addComponent(BotonBorrar)
                .addGap(34, 34, 34)
                .addComponent(BotonSalir)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 398, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(116, Short.MAX_VALUE)
                .addComponent(LabelTitulo)
                .addGap(138, 138, 138))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(LabelTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BotonListar)
                    .addComponent(BotonLeer)
                    .addComponent(BotonBorrar)
                    .addComponent(BotonSalir)
                    .addComponent(EditNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotonSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonSalirActionPerformed

        frmPrincipalAux.setVisible(true);
        this.setVisible(false);
        auxPop3.telnetQuit();
        auxPop3.desconectar();

    }//GEN-LAST:event_BotonSalirActionPerformed

    private void BotonListarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonListarActionPerformed

        TextArea.setText(" ");
        TextArea.setText(auxPop3.telnetList());
      
    }//GEN-LAST:event_BotonListarActionPerformed

    private void BotonLeerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonLeerActionPerformed

        TextArea.setText(" ");
        TextArea.setText(auxPop3.telnetContenido(Integer.parseInt(EditNumero.getText())));

    }//GEN-LAST:event_BotonLeerActionPerformed

    private void BotonBorrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonBorrarActionPerformed

         auxPop3.telnetDele(Integer.parseInt(EditNumero.getText()));
    }//GEN-LAST:event_BotonBorrarActionPerformed

    /**
    * @param args the command line arguments
    */
  /*  public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrameBandejaEntrada().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonBorrar;
    private javax.swing.JButton BotonLeer;
    private javax.swing.JButton BotonListar;
    private javax.swing.JButton BotonSalir;
    private javax.swing.JTextField EditNumero;
    private javax.swing.JLabel LabelTitulo;
    private javax.swing.JTextArea TextArea;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
